package com.app.freshmenapp.service.impl;

import com.app.freshmenapp.dao.PhonesDao;
import com.app.freshmenapp.entity.Phones;
import com.app.freshmenapp.service.PhonesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Auther: Administrator
 * @Date: 2019.07.20 17:07
 * @Description: 常用联系方式服务层
 */

@Service
@SuppressWarnings("all")
public class PhonesServiceImpl implements PhonesService {

    @Autowired
    private PhonesDao phonesDao;

    @Override
    public boolean addPhones(Phones phones) {
        Phones phones1 = phonesDao.saveAndFlush(phones);
        if (phones1!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean deletePhones(Integer id) {
        if(phonesDao.existsById(id)){
            phonesDao.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean updatePhones(Phones phones) {
        Phones phones1 = phonesDao.saveAndFlush(phones);
        if (phones1!=null){
            return true;
        }
        return false;
    }

    @Override
    public Phones findById(Integer id) {
        if (phonesDao.existsById(id)){
            Optional<Phones> optionalPhones=phonesDao.findById(id);
            return optionalPhones.get();
        }
        return null;
    }

    @Override
    public List<Phones> findAllPhones() {
        return phonesDao.findAll();
    }
}
